<?php
class google_api extends CI_Model{
	
	public function __construct(){
		parent::__construct();
	}

	public function google_Image($wordsearch){
		$ip_addr = $this->input->ip_address();
		$url = "https://ajax.googleapis.com/ajax/services/search/images?" .
				"v=1.0&q=".$wordsearch."&userip=".$ip_addr;
		echo $url;
		// sendRequest
		// note how referer is set manually
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_REFERER,"http://dict.1deutsch.info");
		$body = curl_exec($ch);
		curl_close($ch);
		
		print_r(json_decode($body));
		die();
		
		// now, process the JSON string
		return json_decode($body);
	}
	
	public function google_Image_List($list_word_search){		
		$result = array(array());
		foreach ($list_word_search as $wordsearch )
		{
			$result[] = $this->google_Image($wordsearch["word"]);
		}
		return $result;
		
	}
}

?>